import type { Ref } from "vue";

export default function OperationHook(state: {
	priceList: Ref<Base.CommonData[]>;
	formState: any;
}) {
	const { priceList, formState } = state;
	const buyHandle = () => {
		uni.requestPayment({
			provider: "wxpay",
			paySign: "EE987459B9CFF6462462147130110D31",
			signType: "MD5",
			timeStamp: Date.now().toString(),
			noncestr: "6N47VnR42bqIm4xq",
			package: "Sign=WXPay",
			orderInfo: {
				name: "包间",
				price: 100
			},
			success(res) {
				console.log("支付成功", res);
			},
			fail(res) {
				console.log("支付失败", res);
			}
		});
	};
	// 修改套餐
	const changePriceHandle = () => {
		const date = new Date();
		formState.startTime = `${date.getHours()}:${date.getMinutes()}`;
		const addHour =
			priceList.value.find((item: any) => item.value == formState.price)?.hour || 4;
		let endTimeHour = date.getHours() + addHour;
		if (endTimeHour >= 24) {
			endTimeHour -= 24;
			if (endTimeHour < 10) {
				endTimeHour = "0" + endTimeHour;
			}
		}
		formState.endTime = `${endTimeHour}:${date.getMinutes()}`;
		console.log("修改时间11", formState.startTime, formState.endTime);
	};
	return {
		buyHandle,
		changePriceHandle
	};
}
